import { ExecutionContext, Injectable } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { Observable } from 'rxjs'
import { Reflector } from '@nestjs/core'
import { PUBLIC_KEY } from '../constant/decorator.constant'
@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {
  constructor(private readonly reflector: Reflector) { 
    super()
  }
  canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
    const noInterception = this.reflector.getAllAndOverride(PUBLIC_KEY, [context.getHandler(), context.getClass()])
    if (noInterception) return true
    return super.canActivate(context)
  }
}
